﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace mns
{
    /// <summary>
    /// Interaction logic for OneParameterInputDialog.xaml
    /// </summary>
    public partial class OneParameterInputDialog : Window
    {
        public OneParameterInputDialog(string title, string paramname,int value)
        {
            InitializeComponent();
            this.Title = title;
            paramlable.Content = paramname;
            param.Text = Convert.ToString(value);
            
        }

        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancleButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void param_TextChanged(object sender, TextChangedEventArgs e)
        {
            //
            if (System.Text.RegularExpressions.Regex.IsMatch(param.Text, "[^0-9]"))
            {
                MessageBox.Show("Please enter only numbers.");
                String str = param.Text;
                
                for(int i=0;i<str.Length;i++)
                {
                    if(!char.IsDigit(str[i]))
                    {
                        param.Text = str.Remove(i, 1);
                        param.Select(i, 0);
                        break;
                    }
                }
                
            }
            

            if(param.Text.Length == 0)
            {
                param.Text = "0";
            }
            else if(Convert.ToInt32(param.Text)>240)
            {
                MessageBox.Show("Please input no more than 240 minutes.");
                param.Text = "240";
            }


        }
    }
}
